﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using FluentAop;
using FluentAop.Interceptors;
using Proxi;

namespace FluentAOPDemo
{
    class Program
    {
        static void Main(string[] args)
        {

            MethodWrapper wrapper = new MethodWrapper();

            var watch = new Stopwatch();
            wrapper.OnAfter(() =>
                {
                    watch.Stop();
                    Console.WriteLine(watch.ElapsedMilliseconds + " ms");
                    Console.WriteLine("--OnAfter--");
                });


            wrapper.OnBefore(() =>
                {
                    watch.Start();
                    Console.WriteLine("--OnBefore--");
                });

          

            //new Proxy<

            IFoo foo = new Proxy<IFoo>()
            .Target(new Foo())
                //.InterceptMethod(f => f.Go())
            .InterceptWhere(m => m.GetCustomAttributes(typeof(ExcuteTimeAttribute), true).Any())
            .With(wrapper
                //m =>
                //{

                //    var watch = new Stopwatch();
                //    m.OnBefore(() =>
                //        {
                //            watch.Start();
                //            Console.WriteLine("--OnBefore--");
                //        });
                //    m.OnAfter(() =>
                //        {
                //            watch.Stop();
                //            Console.WriteLine(watch.ElapsedMilliseconds + " ms");
                //            Console.WriteLine("--OnAfter--");
                //        });

                //}
                ).Save();

            foo.Go();

            foo.Overloaded(2);
            Console.ReadKey();
        }
    }





    public class Foo : IFoo
    {
        public string Name { get; set; }

        public void Go()
        {
            Thread.Sleep(500);
            Console.WriteLine("Go!");
        }

        public void Throw()
        {
            throw new Exception();
        }

        public string Null()
        {
            return null;
        }

        public void Overloaded(int i)
        {
            Console.WriteLine(i);
        }

        public void Overloaded(string s)
        {
            Console.WriteLine(s);
        }
    }

    public interface IFoo
    {
        string Name { get; set; }
        [ExcuteTime]
        void Go();
        void Throw();
        string Null();

        void Overloaded(int i);
        void Overloaded(string s);
    }
}
